home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dr.bub / 96000.lha / 96000 / appb / b128.asm < prev    next >
Assembly Source File  |  1992-04-28  |  9KB  |  160 lines

  1. ; This program was originally published in the Motorola DSP96002 Users Manual
  2. ; and is provided under a DISCLAIMER OF WARRANTY available from Motorola DSP
  3. ; Operation, 6501 William Cannon Drive West, Austin, Texas 78735-8598.  For
  4. ; more information, refer to the DSP96002 Users Manual, Appendix B, DSP
  5. ; Benchmarks.
  6. ;
  7. ; B.1.28    Bit Field Extraction/Insertion  
  8. ;The process of bit field extraction is performed on a 32 bit integer in  the lower part of a register. A 
  9. ;bit field of length FSIZE starting at  bit position FOFF is extracted and right justified with zero or 
  10. ;sign  extension. The value of FSIZE ranges from 1-32 and the field offset  ranges from 0-31.  Bit 
  11. ;field extraction and insertion operations are  used in high level languages such as "structures" in C. 
  12. ;Both the static  case (extraction based on fixed constants) and the dynamic case  (extraction based 
  13. ;on the values in registers) are given.  In the  examples, the field to be extracted is in d0.l.  
  14. ;The process of bit field insertion is performed on two 32 bit integer  registers.  A bit field of length 
  15. ;FSIZE from one register is shifted  left by an offset FOFF and the field is then inserted into the sec-
  16. ;ond  register. The field size FSIZE ranges from 1-32 and the field offset  from the right of the regis-
  17. ;ter ranges from 0-31.  For meaningful  results, FSIZE+FOFF is less than or equal to 32. The bit field 
  18. ;to  insert is right justified in the register with zero extension to 32  bits. Both the static case 
  19. ;(extraction based on fixed constants) and  the dynamic case (extraction based on the values in regis-
  20. ;ters) are  given.  In the examples, the field in d1.l is inserted into d0.l.  
  21. ;1.     Static bit field extraction, zero extend.  
  22. ;
  23. ;                                                           Program    ICycles
  24. ;                                                              Words      
  25. lsl    #32-(foff+fsize),d0   ;shift off upper bits    1       1      
  26. lsr    #32-fsize,d0          ;right justify           1       1
  27.  ;                                                    ---     ---
  28.  ;                                            Totals:  2       2  
  29.  
  30.  
  31. ;2.     Static bit field extraction, sign extend.  
  32. ;
  33. ;                                                           Program    ICycles
  34. ;                                                              Words
  35. lsl    #32-(foff+fsize),d0   ;shift off upper bits    1       1
  36. asr    #32-fsize,d0          ;right justify, sign ext 1       1
  37. ;                                                     ---     ---
  38. ;                                             Totals:  2       2  
  39.  
  40.  
  41. ;3.     Dynamic bit field extraction, zero extend.  Register d1.l contains 
  42. ;FOFF,  d2.l contains FSIZE.  
  43.  
  44.  
  45. ;                                                           Program    ICycles
  46. ;                                                              Words
  47. move             #32,d3.l    ;register size           1       1      
  48. sub    d2,d3                 ;32-fsize                1       1      
  49. sub    d1,d3     d3.l,d4.h   ;32-fsize-foff, 32-fsize 1       1      
  50. move             d3.l,d0.h   ;move 32-fsize-foff      1       1      
  51. lsl    d0,d0     d4.h,d0.h   ;shift off upper bits    1       1      
  52. lsr    d0,d0                 ;right justify           1       1
  53. ;                                                     ---     ---
  54. ;                                             Totals:  6       6  
  55.  
  56.  
  57. ;4.     Dynamic bit field extraction, sign extend. Register d1.l  contains 
  58. ;FOFF, d2.l contains FSIZE.  
  59.  
  60.  
  61. ;                                                           Program    ICycles
  62. ;                                                              Words
  63. move             #32,d3.l    ;register size           1       1      
  64. sub    d2,d3                 ;32-fsize                1       1      
  65. sub    d1,d3     d3.l,d4.h   ;32-fsize-foff, 32-fsize 1       1      
  66. move             d3.l,d0.h   ;move 32-fsize-foff      1       1      
  67. lsl    d0,d0     d4.h,d0.h   ;shift off upper bits    1       1      
  68. asr    d0,d0                 ;right justify           1       1
  69.  ;                                                    ---     ---
  70.  ;                                            Totals:  6       6  
  71.  
  72.  
  73. ;5.     Static bit field insertion.  
  74. ;
  75. ;
  76. ;                                                           Program    ICycles
  77. ;                                                              Words
  78. move            #-1,d2.l        ;get all ones mask       1      1     
  79. lsl     #32-fsize,d2            ;keep field fsize long   1      1     
  80. lsr     #32-(fsize+foff),d2     ;move to insertion       1      1     
  81. andc    d2,d0                   ;clear field             1      1     
  82. lsl     #foff,d1                ;move field to insert    1      1     
  83. or      d1,d0                   ;insert bit field        1      1
  84. ;                                                        ---    ---
  85. ;                                                Totals:  6      6  
  86.  
  87.  
  88. ;6.     Dynamic bit field insertion.  Register d2.l contains FOFF, d3.l con-
  89. ;tains  FSIZE.  
  90. ;
  91.  
  92. ;                                                           Program    ICycles
  93. ;                                                              Words
  94. move           #32,d4.l        ;get 32                  1     1      
  95. sub    d3,d4   #-1,d5.l        ;32-fsize, load 1's mask 2     2      
  96. sub    d2,d4   d4.l,d5.h       ;32-(fsize+foff)         1     1      
  97. lsl    d5,d5   d4.l,d5.h       ;shift one's mask up     1     1      
  98. lsr    d5,d5                   ;shift one's mask down   1     1      
  99. andc   d5,d0   d2.l,d1.h       ;invert mask and clear   1     1      
  100. lsl    d1,d1                   ;move bits to field      1     1      
  101. or     d1,d0                   ;insert bit field        1     1
  102. ;                                                       ---   ---
  103. ;                                               Totals:  9     9  
  104.  
  105. ;7.     Static bit field clear.  
  106.  
  107. ;                                                           Program    ICycles
  108. ;                                                              Words
  109. move               #-1,d1.l    ;mask of all 1s        1       1      
  110. lsr    #32-fsize,d1            ;make 1s size of foff  1       1      
  111. lsl    #foff,d1                ;align field           1       1      
  112. andc   d1,d0                   ;invert mask and clear 1       1
  113. ;                                                     ---     ---
  114. ;                                             Totals:  4       4  
  115.  
  116.  
  117. ;8.     Static bit field set.  
  118. ;
  119.  
  120. ;                                                           Program    ICycles
  121. ;                                                              Words
  122. ;move               #-1,d1.l    ;mask of all 1s        1       1      
  123. lsr    #32-fsize,d1            ;make 1s size of foff  1       1      
  124. lsl    #foff,d1                ;align field           1       1      
  125. or     d1,d0                   ;clear field           1       1
  126.  ;                                                    ---     ---
  127.  ;                                            Totals:  4       4  
  128.  
  129.  
  130. ;9.     Dynamic bit field clear. Register d1.l contains FOFF, d2.l contains  
  131. ;FSIZE.  
  132.  
  133.  
  134. ;                                                           Program    ICycles
  135. ;                                                              Words
  136. move                #32,d3.l    ;register size          1     1      
  137. sub     d2,d3       #-1,d2.l    ;32-fsize, get 1s mask  2     2      
  138. move                d3.l,d3.h   ;move shift count       1     1      
  139. lsr     d3,d2       d1.l,d1.h   ;trim mask, get foff    1     1      
  140. lsl     d1,d2                   ;align mask             1     1      
  141. andc    d2,d0                   ;invert mask and clear  1     1
  142. ;                                                       ---   ---
  143. ;                                               Totals:  7     7  
  144.  
  145.  
  146. ;10.     Dynamic bit field set. Register d1.l contains FOFF, d2.l contains 
  147. ;FSIZE.  
  148.  
  149.  
  150. ;                                                           Program    ICycles
  151. ;                                                              Words
  152. move                #32,d3.l    ;register size          1     1      
  153. sub     d2,d3       #-1,d2.l    ;32-fsize, get 1s mask  2     2      
  154. move                d3.l,d3.h   ;move shift count       1     1      
  155. lsr     d3,d2       d1.l,d1.h   ;trim mask, get foff    1     1      
  156. lsl     d1,d2                   ;align mask             1     1      
  157. or      d2,d0                   ;clear bit field        1     1
  158. ;                                                       ---   ---
  159. ;                                               Totals:  7     7  
  160.